{include file="index/head" /}
<div class="box">
	<div class="box-head">
		<ul class="search">
		<li>文件列表</li>
		<li>
		<select onchange="change(this.value)">
			<option value="1" {if condition="$type eq 1"}selected{/if}>模板文件</option>
			<option value="2" {if condition="$type eq 2"}selected{/if}>样式文件</option>
		</select>
		</li>
		</ul>
		<div class="fr">
			<a href="javascript:history.go(-1);" class="btn fr"><i class="icon-mail-reply (alias)"></i>返回</a>
		</div>
	</div>
	<p style="margin-bottom:10px;">
	{if condition="$file neq ''"}	
	<a href="javascript:history.go(-1)" class="btn"><i class="icon-mail-reply (alias)"></i>返回上级目录</a>
	{/if}
	当前目录：{$dir}	
	</p>
	<ul class="fileList">
		<li>
			<div class="fl">
				<h3>文件名</h3>
				<span>文件大小</span>
				<span>修改时间</span>
			</div>
			操作
		</li>
		{volist name="list" id="v"}
		{php}					
			if($v['icon']=='file'){
				$href = url('Tpl/fileindex',['id'=>$id,'type'=>$type]).'?file='.$v['file'];
			}else{
				if($v['edit']==1){
					$href = "javascript:void(0);";
				}else{
					$href = '/static'.$v['src'];
				}
			}
		{/php}
		<li>
			<div class="fl">
				<h3><a href="{$href}" file="{$v.src}" {eq name="v.edit" value="1"}class="dofileedit"{/eq} {if condition="$v.icon neq 'file' && $v.edit neq 1"}target="_blank"{/if}><img src="/public/admin/images/file/{$v.icon}.png" alt="">{$v.name}</a></h3>						
				<span>{$v.size}</span>
				<span>{$v.updatetime}</span>
			</div>
			{if condition="$v.edit eq 1"}
			<a href="javascript:void(0);" file="{$v.src}" class="dofileedit" class="fr"><i class="icon-pencil-square-o"></i> 编辑</a>
			{else}
				{if condition="$v.icon neq 'file'"}
				<a href="/static{$v.src}" target="_blank" class="fr"><i class="icon-eye"></i> 查看</a>
				{/if}
			{/if}
		</li>		
		{/volist}
	</ul>		
</div>
<script>
//选择样式或模板
function change(type){
	window.location.href = "{:url('fileindex')}?id={$id}&type="+type;
}
//编辑文件
$(document).on('click','.dofileedit', function () {
	var file = $(this).attr("file");
	var type = '{$type}'
	$.get("{:url('Tpl/exitfile')}",{type,file},function(res){
			if(res.status=='y'){
				layer.open({
					 title: '编辑文件 '+ file,
					 type: 2,
					 skin: 'layer_diqu',
					 area: ['1000px','600px'],
					 maxmin : true,
					 content: '{:url("acefile")}?file='+ file+'&type={$type}',
					 btn: ['保存','关闭'],
					 yes: function(index, layero){
					 	var iframeWindow=(layero).find("iframe")[0].contentWindow;
					 	iframeWindow.savefile();
					 }
				})
			}else{
				layer.alert(res.info)
			}
	},'json')
	
})
</script>
